package dhm.com.hpx.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.hpx.R;
import dhm.com.hpx.activity.AddspeechcraftActivity;
import dhm.com.hpx.entity.SpeechcraftListBean;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class SpeechcraftAdapter extends RecyclerView.Adapter<SpeechcraftAdapter.ViewHolder> {

    private Context context;


    List<SpeechcraftListBean.DataBean> list=new ArrayList<>();

    public SpeechcraftAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<SpeechcraftListBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_speechcraft, null);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.content.setText(list.get(i).getContent());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick.item(i);
            }
        });

        viewHolder.cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onIntentClick.item(i);
            }
        });

        viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                Intent intent=new Intent(context, AddspeechcraftActivity.class);
                intent.putExtra("content",list.get(i).getContent()+"");
                intent.putExtra("speechcraft_id",list.get(i).getSpeechcraft_id()+"");
                intent.putExtra("type","4");
                context.startActivity(intent);
                return true;
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView content;
        public ImageView cancle;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            content=itemView.findViewById(R.id.content);
            cancle=itemView.findViewById(R.id.cancle);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int posttion);
    }



}

